package com.course.db;

import java.sql.ResultSet;

public class ChooseCourse extends ExecuteDB {

	//members
	private int Id;
	private int student_id;
	private int course_id;
	private int status;
	private String score;
	private String strSql;
	
	public ChooseCourse()
	{
		this.Id = 0;
		this.student_id = 0;
		this.course_id = 0;
		this.status = 0;
		this.score = "";
	}
	
	public String CountSql()
	{
		this.strSql = "select count(*) from choose_course";
		return this.strSql;
	} 
	
	//add a ChooseCourse
	public boolean add()
	{

		this.strSql="insert into choose_course ";
		this.strSql=this.strSql + "(student_id,course_id,status,score) ";
		this.strSql=this.strSql + "values(" + this.student_id + "," + this.course_id + "," + this.status+ ",'" + this.score + "')";
		System.out.println(this.strSql);
		boolean isAdd = super.exeSql(this.strSql);
        return isAdd;
	}
	
	public int lastid()
	{
		int lid = 0;
		this.strSql = "select last_insert_id() as id from choose_course limit 1";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
			if (rs.next())
				lid = rs.getInt("id");
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return lid;
	}
	
	//delete a ChooseCourse by id
    public boolean delete(int ChooseCourseID)
    {
       this.strSql = "delete from choose_course where Id in (";
       this.strSql = this.strSql + ChooseCourseID +")";

       boolean isDelete = super.exeSql(this.strSql);
       return isDelete;
    }
    
  //initialize ChooseCourse information
 	public boolean init()
	{
		this.strSql="select * from `choose_course` where Id=";
		this.strSql=this.strSql + "'" + this.Id + "'";

		try
		{
			ResultSet rs = super.exeQuery(this.strSql);
			if (rs.next())
			{
				this.Id=rs.getInt("Id");
				this.student_id=rs.getInt("student_id");
				this.course_id=rs.getInt("course_id");
				this.status=rs.getInt("status");
				this.score=rs.getString("score");
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
			return false;
		}
	}
 	
 	//modify ChooseCourse infomation
    public boolean modify_choose_course()
	{
		this.strSql="update choose_course set";
		this.strSql=this.strSql + " student_id=" + "'" + this.student_id + "',";
		this.strSql=this.strSql + " course_id=" + "'" + this.course_id + "',";
		this.strSql=this.strSql + " status=" + this.status + ",";
		this.strSql=this.strSql + " score=" + this.score ;
		this.strSql=this.strSql + " where Id=" + this.Id;
		
		boolean isUpdate = super.exeSql(this.strSql);

		return isUpdate;
	}
 	
 	//show ChooseCourse
    public ResultSet show_choose_course()
	{
		this.strSql="select * from `choose_course`";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return rs;
	}

	public int getId() {
		return Id;
	}

	public void setId(int id) {
		Id = id;
	}

	public int getStudent_id() {
		return student_id;
	}

	public void setStudent_id(int student_id) {
		this.student_id = student_id;
	}

	public int getCourse_id() {
		return course_id;
	}

	public void setCourse_id(int course_id) {
		this.course_id = course_id;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getScore() {
		return score;
	}

	public void setScore(String score) {
		this.score = score;
	}

	public String getStrSql() {
		return strSql;
	}

	public void setStrSql(String strSql) {
		this.strSql = strSql;
	}

    
}
